package com.fdd.op.demo;

import com.fdd.op.sdk.ApiException;
import com.fdd.op.sdk.DefaultFddClient;
import com.fdd.op.sdk.constants.Constants;
import com.fdd.op.sdk.internal.token.FddTokenStore;
import com.fdd.op.sdk.internal.token.stroe.CacheTokenStoreImpl;
import com.fdd.op.sdk.internal.util.json.JSONWriter;
import com.fdd.op.sdk.model.vo.WidgetValueVo;
import com.fdd.op.sdk.request.api.account.GetAccountRequest;
import com.fdd.op.sdk.request.api.file.CreateFileRequest;
import com.fdd.op.sdk.response.api.account.GetAccountResponse;
import com.fdd.op.sdk.response.api.file.CreateFileResponse;

import java.util.ArrayList;
import java.util.List;

/**
 * @description: 定制-使用模板创建合同文档
 * @author lijiaxin@fadada.com
 * @date 2023/8/23 11:17
 */
public class CreateFileApi {
    private static String serverUrl = "http://10.21.8.20:37801/";
    private static final String appId = "486478";
    private static final String appKey = "xguUMVFnDzqJgfVEDnLW16yE2mxVL2Fp";

    public static void main(String[] args) throws ApiException {
        FddTokenStore tokenStore = new CacheTokenStoreImpl();
        DefaultFddClient fddClient = new DefaultFddClient(serverUrl, appId, appKey, Constants.AUTH_OAUTH, 1000, 30000);
        fddClient.tokenStore(tokenStore);
        CreateFileRequest request = new CreateFileRequest();
        request.setTemplateNo("template202301");
        List<WidgetValueVo> list = new ArrayList();
        WidgetValueVo widgetValue = new WidgetValueVo();
        widgetValue.setCode("test1");
        widgetValue.setValue("单行文本框");
        list.add(widgetValue);
        list.add(new WidgetValueVo("test2","多行文本框"));
        list.add(new WidgetValueVo("test3","true"));
        list.add(new WidgetValueVo("test4","[{\"table1\":\"A1\",\"table2\":\"A2\",\"table3\":\"A3\"}]"));
        request.setWidgetValues(list);
        CreateFileResponse response = fddClient.execute(request);
        if(response != null && "0".equals(response.getCode())){
            System.out.println(response.getData());
        }
    }
}
